﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;

using Hubble.SQLClient;

namespace HubbleDataAccess
{
    /// <summary>
    /// 时间：2012年10月11日 23:52:42
    /// 备注：访问 Hubble 索引接口
    /// </summary>
    public class HubbleDBAccess
    {
        /// <summary>
        /// 查询 Hubble返回单个表
        /// </summary>
        /// <param name="hubbleSql"></param>
        /// <returns></returns>
        public static DataTable ExecuteDataTable(string hubbleSql)
        {
            DataTable resultTable = null;
            using (HubbleConnection conn = new HubbleConnection(ConstantHelper.HubbleConnString))
            {
                HubbleCommand cmd = new HubbleCommand(conn);
                cmd.CommandText = hubbleSql;
                resultTable = cmd.Query().Tables[0];
            }
            return resultTable;
        }

        /// <summary>
        /// 获取过滤值
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="fieleName"></param>
        /// <param name="searchKeywords"></param>
        /// <param name="wordSplitBySpace"></param>
        /// <returns></returns>
        public static string GetKeywordAnalyzerString(string tableName, string fieleName, string searchKeywords,out string wordSplitBySpace)
        {
            return GetKeywordAnalyzerString(tableName, fieleName, searchKeywords,out  wordSplitBySpace, int.MaxValue);
        }

        /// <summary>
        /// 获取过滤值
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="fieldName"></param>
        /// <param name="searchKeywords"></param>
        /// <param name="wordSplitBySpace"></param>
        /// <param name="cacheTimeout"></param>
        /// <returns></returns>
        public static string GetKeywordAnalyzerString(string tableName,string fieldName,string searchKeywords,out string wordSplitBySpace,int cacheTimeout)
        {
            string str = string.Empty;
            using (HubbleConnection conn = new HubbleConnection(ConstantHelper.HubbleConnString))
            {
                HubbleCommand cmd = new HubbleCommand(conn);
                str = cmd.GetKeywordAnalyzerStringFromServer(tableName, fieldName, searchKeywords, cacheTimeout, out wordSplitBySpace);
            }
            return str;
        }
    }
}
